package cn.tianyigps.tianyigpsmiletask.assign;

import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import org.springframework.stereotype.Component;

/**
 * 里程计算
 */
public class MileageCalculation {
    /**
     * 根据经纬度获取两点之间的距离(单位：KM)
     * @return
     */
    public static double calcDistance(double lng1 , double lat1, double lng2, double lat2) {
        // 计算两定位之间距离
        SpatialContext geo = SpatialContext.GEO;
        return geo.calcDistance(geo.makePoint(lng1,lat1),geo.makePoint(lng2, lat2)) * DistanceUtils.DEG_TO_KM;
    }
}
